import actions from "./actions";
import mutations from "./mutations";
import {createStore} from "vuex";

const store = createStore({
    state: {
        navBarList: [],
        viewList: [],
        userInfo: {},
        permissionMenus: []
    },
    getters: {
        /**
         * 获取tab菜单
         * @param state
         * @returns {[]}
         */
        getNavData(state) {
            let data = state.navBarList.find(item => item.path === "/home");
            let num = state.navBarList.findIndex(item => item.path === "/home");
            state.navBarList.splice(num, 1);
            state.navBarList.splice(0, 0, data);

            return state.navBarList;
        },
        /**
         * 获取缓存列表
         * @param state
         * @returns {[]}
         */
        getViewCache(state) {
            return state.viewList;
        },
        /**
         * 获取用户信息
         * @param state
         * @returns {((options: {encoding: "buffer"}) => UserInfo<Buffer>) | {} | ((options?: {encoding: BufferEncoding}) => UserInfo<string>)}
         */
        getUserInfo(state) {
            return state.userInfo;
        },
        /**
         * 用户权限菜单
         * @param state
         * @returns {[]}
         */
        getPermissionMenus(state) {
            return state.permissionMenus;
        }
    },
    mutations, actions
});
export default store